/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function onclick_sbt(){
    alert("success");
}

function onkeyup_txtr(obj)
{
    var maxChars = 100;//max number of letters
    if (obj.value.length > maxChars)
        obj.value = obj.value.substring(0,maxChars);
    var curr = maxChars - obj.value.length;
    document.getElementById("count").innerHTML = curr.toString();
}

function onclick_sendPost(){
    if(!confirm("Are You sure to publish the post?")){
        return;
    }
    var txtTitle=document.getElementById("txtTitle").value;
    var sltType=document.getElementById("sltType").value;
    var txtarea=document.getElementById("textarea").value;
    //alert(txtTitle);
    var params={
        "title":txtTitle,
        "type":sltType,
        "detail":txtarea
    };   //pack information into json
    
    //alert(params);
    
    $.ajax({
        url: '../PostServlet',
        type: "POST",
        data: params,
        error: callbackPF,
        success: callbackPT
    });

}

/**
 *call back function used when server call back
 */
function callbackPT(data){
    //alert(data.isPass);
    if(data.isPass=="TRUE"){
        //document.getElementById("serverResponse").innerHTML="<b>Logon Successed<br/><b>Loading......</b>";
        //self.location='test.jsp';
        alert("Post successfully\nPress confirm button to jump");
    }else{     
        //document.getElementById("serverResponse").innerHTML="<b>Logon failed</b><br/><b>Please check email or password</b>";
        alert("FALSE");
    }
}

/**
 *call back function used when server DONOT call back
 */
function callbackPF(data){
    alert("the server does not recall, request failed!");
}